console.log("用户的登录页面");
//导入 css 资源
import "../../css/adminlte.min.css";
import request from "../../utils/request";

//获取表单
let form = document.querySelector("form");
let unameInput = document.querySelector("input[name=uname]");
let pwdInput = document.querySelector("input[name=pwd]");
//表单绑定事件
form.onsubmit = async function (e) {
  //阻止表单提交的默认行为
  e.preventDefault();
  //获取用户填写的账号与密码
  let uname = unameInput.value;
  let pwd = pwdInput.value;
  //发送请求
  let data = await request.post("/login", {
    uname,
    pwd,
  });
  //成功的情况
  alert("登录成功");
  //持久化保存 token
  localStorage.setItem("token", data.token);
  //跳转页面
  location.href = "/users.html";
};
